<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合同表管理列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>合同编号：</p>
                                <input type="text" name="contractNo"/>
                            </li>
                            <li>
                                <p>合同名称：</p>
                                <input type="text" name="contractName"/>
                            </li>
                            <li>
                                <p>销售负责人：</p>
                                <input type="text" name="xsPrincipalName"/>
                            </li>
							<li>
                                <p>交付负责人：</p>
                                <input type="text" name="jfPrincipalName"/>
                            </li>
                            <li>
                                <p>甲方名称：</p>
                                <input type="text" name="partyAName"/>
                            </li>
                            <li>
                                <p>中标方：</p>
                                <input type="text" name="biddingCompany"/>
                            </li>
                            <li class="select-time">
                                <p>中标时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginBiddingTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endBiddingTime]"/>
                            </li>

                            <li>
                                <p>bidding金额：</p>
                                <input type="text" name="biddingMoney"/>
                            </li>
                            <li>
                                <p>项目类型一：</p>
                                <input type="text" name="projectTypeOne"/>
                            </li>
                            <li>
                                <p>项目类型二：</p>
                                <input type="text" name="projectTypeTwo"/>
                            </li>

                            <li>
                                <p>客户：</p>
                                <input type="text" name="customer"/>
                            </li>


                            <li class="select-time">
                                <p>合同签订时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginContractSignTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endContractSignTime]"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:contractDetail:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:contractDetail:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:contractDetail:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:contractDetail:export">
                    <i class="fa fa-download"></i> 导出合同表
                 </a>
                <a class="btn btn-warning" onclick="$.table.exportExcelYingShou()" shiro:hasPermission="system:contractDetail:export">
                    <i class="fa fa-download"></i> 导出应收账款表
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:contractDetail:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:contractDetail:remove')}]];
        var prefix = ctx + "system/contractDetail";
        var prefixStage = ctx + "system/stage";
        var datas = [[${@dict.getType('sys_normal_disable')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                exportUrlYingShou: prefix + "/exportYingShou",
                modalName: "合同表管理",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
					initChildTable(index, row, $detail);
				},
                columns: [{
                    checkbox: true
                },
                {
                    field : 'contractId', 
                    title : '主键id',
                    visible: false
                },
                {
                    field : 'contractNo', 
                    title : '合同编号'
                },
                {
                    field : 'contractName', 
                    title : '合同名称'
                },
				 {
                    field : 'xsPrincipalName', 
                    title : '销售负责人'
                },
                {
                    field : 'jfPrincipalName', 
                    title : '交付负责人'
                },
                {
                    field : 'partyAName', 
                    title : '甲方名称'
                },
                {
                    field : 'biddingCompany', 
                    title : '中标方'
                },
                {
                    field : 'biddingTime', 
                    title : '中标时间'
                },
                {
                    field : 'biddingMoney', 
                    title : 'bidding金额'
                },

                {
                    field : 'xsDepartment', 
                    title : '销售二级部门'
                },
                {
                    field : 'jfDepartment', 
                    title : '交付二级部门'
                },
                {
                    field : 'contractSignTime', 
                    title : '合同签订时间'
                },
                {
                    field : 'booking', 
                    title : 'booking金额'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' 
                        + editFlag 
                        + '" href="javascript:void(0)" onclick="openChildTable(\'' + row.contractId + '\')"><i class="fa fa-edit"></i>添加阶段</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.contractId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.contractId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        openChildTable = function(contractId) {
            $.modal.openOptions({
                title: '添加阶段',
                width: "680",
                url: "./stage/add/" + contractId,
                callBack: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            });
        }
        initChildTable = function(index, row, $detail) {
			var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
    	    $(childTable).bootstrapTable({
    	        url: prefixStage + "/list",
    	        method: 'post',
    	        sidePagination: "server",
    	        contentType: "application/x-www-form-urlencoded",
    	        queryParams : {
                    contractId: row.contractId
				},
    	        columns: [
                {
                    field : 'stageId',
                    title : 'id',
                    visible: false
                },
                {
                    field : 'contractId',
                    title : '合同id'
                },
                {
                    field : 'stageNo',
                    title : '阶段序号'
                },
                {
                    field : 'stageName',
                    title : '阶段名称'
                },
                {
                    field : 'stagePrincipal1',
                    title : '阶段负责人一'
                },
                {
                    field : 'stageMoney',
                    title : '本阶段合同收款金额'
                },

                {
                    field : 'budgetEndTime',
                    title : '销售计划结束时间'
                },

                {
                    field : 'predictEndTime',
                    title : '实施预测结束时间'
                },

                {
                    field : 'actualEndTime',
                    title : '交付实际结束时间'
                },

                {
                    title: '编辑评估',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs '
                            + editFlag
                            + '" href="javascript:void(0)" onclick="openChildEditBudgetTable(\'' + row.stageId + '\')"><i class="fa fa-edit"></i>编辑预算</a> ');
                        actions.push('<a class="btn btn-success btn-xs '
                            + editFlag
                            + '" href="javascript:void(0)" onclick="openChildEditPredictTable(\'' + row.stageId + '\')"><i class="fa fa-edit"></i>编辑预测</a> ');
                        actions.push('<a class="btn btn-success btn-xs '
                            + editFlag
                            + '" href="javascript:void(0)" onclick="openChildEditActualTable(\'' + row.stageId + '\')"><i class="fa fa-edit"></i>编辑实际</a> ');

                        return actions.join('');
                    }
                }]
            });
        };


        var prefixSystem = ctx + "system"
        openChildBudgetTable = function(stageId) {
            $.modal.openOptions({
                title: '选择字典类型',
                width: "680",
                url: prefixSystem + "/budget/add/" + stageId,
                callBack: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            });
        }
        openChildPredictTable = function(stageId) {
            $.modal.openOptions({
                title: '选择字典类型',
                width: "680",
                url: prefixSystem + "/predict/add/" + stageId,
                callBack: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            });
        }
        openChildActualTable = function(stageId) {
            $.modal.openOptions({
                title: '选择字典类型',
                width: "680",
                url: prefixSystem + "/actual/add/" + stageId,
                callBack: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            });
        }
        openChildEditBudgetTable = function(stageId) {
            $.modal.openOptions({
                title: '选择字典类型',
                width: "1280",
                url: prefixSystem + "/budget/editbudget/" + stageId,
                callBack: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            });
        }
        openChildEditPredictTable = function(stageId) {
            $.modal.openOptions({
                title: '编辑预测收款列表',
                width: "1280",
                url: prefixSystem + "/predict/editpredict/" + stageId,
                callBack: function(index, layero) {
                    return true;
                }
            });
        }
        openChildEditActualTable = function(stageId) {
            $.modal.openOptions({
                title: '编辑实际收款列表',
                width: "1280",
                url: prefixSystem + "/actual/editactual/" + stageId,
                callBack: function(index, layero) {
                    close()
                }
            });
        }

        layui.use('laydate', function(){
            var laydate = layui.laydate;
            
            laydate.render({ 
                elem: '#laydate-demo-2',
                type: 'date'
            });
        
        });
    </script>
</body>
</html>